package inheritance;

public class TestExtend {
    public static void eatAnimal(Animal a){
        a.eat();    //向上转型，方法传参,可接收子类对象
    }
    public static Animal seeAnimal1(String s){ //向上转型，方法返回
        if("dog".equals(s)){
            return new Dog("小狗",3);
        }
        if ("cat".equals(s)){
            return new Cat("小猫",2);
        }
        return null;
    }

    public static void main(String[] args) {
        Dog dog = new Dog("豚豚" , 3);
        Cat cat = new Cat("咪咪" , 5);
        Animal dog1 = new Dog("小白",5);  //向上转型，直接赋值
        Animal cat1 = new Cat("小刘海",2);
        dog.bark();
        cat.eat();
        eatAnimal(cat1);    //方法传参的调用
        Animal a = seeAnimal1("cat");

    }
}
